/**
 * @param {number} x
 * @return {number}
 */
var mySqrt = function(x) {
    return Math.floor(realSqrt(x));
};

// 实数二分模板
// ans = realSqrt(x, 1e-6)
// 如果要求4位小数，就多算2~4位，到1e-6或1e-8，保证精确
var realSqrt = function(x, eps=1e-6) {
    let left = 0, right = Math.max(x, 1);
    while (right - left > eps) {
        let mid = (left + right) / 2;
        if (mid * mid <= x) {
            left = mid;
        } else {
            right = mid;
        }
    }
    return right;
}